package com.itheima.config;

import com.itheima.domain.Xmemcached;
import net.rubyeye.xmemcached.MemcachedClient;
import net.rubyeye.xmemcached.MemcachedClientBuilder;
import net.rubyeye.xmemcached.XMemcachedClientBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;

@Configuration
public class XmemcachedConfig {
    /**
     * 创建一个memcached服务端，因为SpringBoot没有整合，所以要自己创建
     * @return
     */
    @Autowired
    private Xmemcached xmemcached;

    @Bean
    public MemcachedClient memcachedClient() throws IOException {
        MemcachedClientBuilder memcachedClientBuilder=new XMemcachedClientBuilder(xmemcached.getAddress());
        memcachedClientBuilder.setConnectionPoolSize(xmemcached.getPoolSize());
        memcachedClientBuilder.setConnectTimeout(xmemcached.getOptimeout());
        MemcachedClient build = memcachedClientBuilder.build();
        return build;
    }

}
